package cn.elwy.rcp.ui.explorer.handler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

import cn.elwy.rcp.ui.dialog.MsgDialog;
import cn.elwy.rcp.ui.explorer.create.wizard.NewBuilderProjectWizard;
import cn.elwy.rcp.ui.wizard.CWizardDialog;

public class NewProjectHandler implements IHandler {

	@Override
	public void addHandlerListener(IHandlerListener handlerListener) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell shell = HandlerUtil.getActiveShell(event);
		try {
			NewBuilderProjectWizard wizard = new NewBuilderProjectWizard();
			CWizardDialog dialog = new CWizardDialog(shell, wizard, NewBuilderProjectWizard.ID);
			return dialog.open();
		} catch (Exception e) {
			return MsgDialog.open(shell, e);
		}
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public boolean isHandled() {
		return true;
	}

	@Override
	public void removeHandlerListener(IHandlerListener handlerListener) {
	}

}
